# client

import socket

class DouyuMsg(object):

    """Docstring for DouyuMsg. """

    def __init__(self,content):
        self.length = bytearray([len(content) + 9, 0x00, 0x00, 0x00])
        self.code = self.length
        self.magic = bytearray([0xb1, 0x02, 0x00, 0x00])
        self.content = bytes(content.encode("utf-8"))
        self.end = bytearray([0x00])


    def get_bytes(self):
        return bytes(self.length + self.code + self.magic + self.content + self.end)


address = ('openbarrage.douyutv.com', 8601)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(address)

s.send(DouyuMsg('type@=loginreq/roomid@=699007/').get_bytes())
data = s.recv(512)
print('the data received is', data)
# s.send(DouyuMsg('type@=joingroup/rid@=699007/gid@=-9999/').get_bytes())
# data = s.recv(512)
# print('the data received is', data)
s.close()
